﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HSYCWeb.Common;
using System.Data;
using HSYCControl.web;

namespace HSYCWeb.web.xwht
{
    public partial class YC_NewType : Pages
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                buildGrid();
            }
        }

        public DataSet buildGrid()
        {
            DataSet ds = new DataSet();
            try
            {
                base.o_uiTable.Clear();
                base.o_uiTable.Add("XMMC", MtxtD_XMMC.Text.Trim());
                base.o_uiTable.Add(c_obj.p_uiStatic, true);
                YC_Xwlb_Control control = new YC_Xwlb_Control();
                ds = control.f_listQuery(ref base.o_uiTable, ref base.o_errMsg, ref base.o_errState, ref base.o_baseTable);
                DataTable dbItem = ds.Tables[0];
                int TotalCount = 0;//总记录数
                int TotalPage = 1; //总页数
                TotalCount = dbItem.Rows.Count;
                PagedDataSource PDS = new PagedDataSource();
                PDS.DataSource = dbItem.DefaultView;
                PDS.AllowPaging = true;
                PDS.PageSize = 15;
                int CurrentPage;
                if (Request.QueryString["Page"] != null)
                {
                    CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
                }
                else
                {
                    CurrentPage = 1;
                }

                if (TotalCount % PDS.PageSize == 0)
                {
                    TotalPage = TotalCount / PDS.PageSize;
                }
                else
                {
                    TotalPage = TotalCount / PDS.PageSize + 1;
                }
                if (TotalPage == 0)
                {
                    TotalPage = 1;
                }
                //   当前页所引为页码-1
                PDS.CurrentPageIndex = CurrentPage - 1;

                lblCurrentPage.Text = "共" + TotalCount.ToString() + "条记录 当前页：" + CurrentPage.ToString() + "/" + TotalPage;

                //

                lnkEnd.Visible = true;
                lnkFrist.Visible = true;
                lnkNext.Visible = true;
                lnkEnd.Visible = true;

                //
                if (CurrentPage <= 1)
                {
                    lnkFrist.Visible = false;
                    lnkPrev.Visible = false;
                }
                if (CurrentPage >= TotalPage)
                {
                    lnkNext.Visible = false;
                    lnkEnd.Visible = false;
                }

                lnkFrist.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
                lnkEnd.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + TotalPage;

                if (!PDS.IsFirstPage)
                {
                    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1);
                }
                if (!PDS.IsLastPage)
                {
                    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1);
                }


                this.Repeater1.DataSource = PDS;
                this.Repeater1.DataBind();


            }
            catch (System.Exception ee)
            {
                //m_loger.Error(o_logTitle + "菜单模块查询失败！", ee);
            }
            return ds;
        }




        protected void jsCall_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            try
            {
                string id = base.f_convertString(e.Parameters[1]);
                if (base.f_convertString(e.Parameters[0]) == "del")    //删除操作
                {
                    base.o_uiTable.Clear();
                    base.o_uiTable.Add("ID", base.f_convertGuid(id));
                    base.o_uiTable.Add(c_obj.p_uiStatic, true);
                    YC_Xwlb_Control control = new YC_Xwlb_Control();
                    control.f_deleteData(ref base.o_uiTable, ref base.o_errMsg, ref base.o_errState, ref base.o_baseTable);
                    m_loger.Info(o_logTitle + "删除" + base.f_convertString(e.Parameters[2]) + "申报项目成功！");
                }
                else if (base.f_convertString(e.Parameters[0]) == "search")   //搜索操作
                {

                }
            }
            catch (System.Exception pexp)
            {

            }
            //最后进行Grid数据查询并填充
            finally
            {
                buildGrid();
                Panel1.RenderControl(e.Output);
            }
        }
    }
}